package com.tonyodev.fetch2core;

import java.io.Closeable;
import java.io.IOException;

/**
 * Class that can be used to wrap an INPUT Stream of file input resource.
 *
 * @since 2021-05-20
 */
public abstract class InputResourceWrapper implements Closeable {
    /**
     * read bytes from resource
     *
     * @param byteArray data
     * @param offSet read offset
     * @param length data length
     * @return 返回值
     * @throws IOException io fail
     */
    public abstract int read(byte[] byteArray, int offSet, int length) throws IOException;

    /**
     * read bytes from resource
     *
     * @param byteArray data
     * @return 返回值
     * @throws IOException io fail
     */
    public int read(byte[] byteArray) throws IOException {
        return read(byteArray, 0, byteArray.length);
    }

    /**
     * Set read offset position
     *
     * @param offset read offset position
     * @throws IOException io fail
     */
    public abstract void setReadOffset(long offset) throws IOException;
}
